package com.des1gn.ymgetil;

import com.des1gn.ymgetil.enums.YmBigTypeEnums;
import com.des1gn.ymgetil.model.MiaoSubmitDto;
import com.des1gn.ymgetil.model.TaskModel;
import com.des1gn.ymgetil.model.UserInfoModel;
import com.des1gn.ymgetil.service.*;
import com.des1gn.ymgetil.util.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName BasicController
 * @Description TODO
 * @Author Des1gn
 * @Date 2021/11/25 11:33
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ym")
@CrossOrigin(origins = "*")
public class BasicController {

    @Autowired
    TaskService taskService;

    @Autowired
    UserInfoService userInfoService;

    @Autowired
    SmallTypeService smallTypeService;

    @Autowired
    ProxyService proxyService;

    @Autowired
    MiaoService miaoService;

    @PostMapping("addTask")
    public ResultModel addTask(@RequestBody TaskModel taskModel){
        taskService.addTask(taskModel);
        return ResultModel.createSuccess("success");
    }

    @GetMapping("getTasks")
    public ResultModel getTasks(){
        return ResultModel.createSuccess(taskService.getTaskList());
    }

    @GetMapping("removeTask")
    public ResultModel removeTask(String id){
        taskService.removeTask(id);
        return ResultModel.createSuccess();
    }

    /**
     * 添加用户
     * @param sessionId
     * @return
     */
    @GetMapping("getUserInfo")
    public ResultModel getUserInfo(String sessionId){
        UserInfoModel userInfo = userInfoService.getUserInfo(sessionId);
        return ResultModel.createSuccess(userInfo);
    }

    /**
     * 查询用户列表
     * @return
     */
    @GetMapping("getUserList")
    public ResultModel getUserList(){
        List<UserInfoModel> userInfos = userInfoService.getUserInfoList();
        return ResultModel.createSuccess(userInfos);
    }

    /**
     * 删除用户
     * @param sessionId
     * @return
     */
    @GetMapping("delUserInfo")
    public ResultModel delUserInfo(String sessionId){
        Boolean isOk = userInfoService.removeUserInfo(sessionId);
        return ResultModel.createSuccess(isOk);
    }

    /**
     * 查询类型
     * @return
     */
    @GetMapping("getType")
    public ResultModel getType(String sessionId){
        return ResultModel.createSuccess(smallTypeService.getSmallTypes(sessionId, YmBigTypeEnums.getCode("hpv")));
    }

    /**
     * 查询医院
     * @return
     */
    @GetMapping("getHospitals")
    public ResultModel getHospitals(String sessionId,String type){
        return ResultModel.createSuccess(smallTypeService.getHospitals(sessionId,type));
    }

    /**
     * 查询医院
     * @return
     */
    @GetMapping("getProducts")
    public ResultModel getProducts(String sessionId,String hospitalId){
        return ResultModel.createSuccess(smallTypeService.getProducts(sessionId,hospitalId));
    }


    /**
     * 刷新代理池
     * @return
     */
    @GetMapping("flushProxys")
    public ResultModel flushProxys(){
        return ResultModel.createSuccess(proxyService.createProxys());
    }

    /**
     * 提交抢购申请
     * @return
     */
    @PostMapping("submitOrderRequest")
    public ResultModel<String> submitOrderRequest(@RequestBody MiaoSubmitDto miaoSubmitDto){
        taskService.doMiaoTask(miaoSubmitDto);
        return ResultModel.createSuccess("申请提交成功");
    }


}
